
local w,h = 400,400
local w1,h1 = 380,50
class.dialog_ui = extends(class.panel)
{
    fdf = 'tooltip_backdrop2',
    alpha = 0.99,
    show_flag = false,
    init = function (self)
        class.panel.init(self)
        
        self.title = self:add_text(self.name,0,10,nil,30,16,5)
        self.buttons = {}
        for a=1,10 do
            local button = self:add_button('',(w-w1)/2,50 + (a-1)*(h1+5),w1,h1)
            button.index = a
            class.panel:builder {
                parent = button,
                fdf = 'tooltip_backdrop1',
            }
            button.title = button:add_text('5%概率造成额外对目标范围触发一次伤害',0,10,nil,30,12,5)
            self.buttons[a] = button
        end
        self:set_ignore_trackevents(false)
        return self
    end,
    new = function (parent,name)
        local panel = class.dialog_ui:builder 
        {
            name = name,
            x = (1920-w)/2,
            y = 200,
            w = w,
            h = h,
        }
        return panel
    end,

    on_button_clicked = function(self,button)
        local name = ('对话框-%s'):format(self.name)
        ac.sync(name,button.index)
        self:hide()
    end,

    --进入
    on_button_mouse_enter = function(self,button)
        self.old_select = button
        self.old_select.title:set_color(0xff00ff00)
    end,
    --离开
    on_button_mouse_leave = function(self)
        if self.old_select then
            self.old_select.title:set_color(0xffffffff)
        end
    end,
    --设置
    set_data = function(self,player,data)
        if not player:is_self() then
            return
        end

        if self.old_select then
            self.old_select.title:set_color(0xffffffff)
        end
        
        for i,button in ipairs(self.buttons) do
            local info = data[i]
            if info then
                button.title:set_text(info.tip)
                button:show()
            else
                button:hide()
            end
        end

        self:set_height(#data*55 + 80)
        self:set_position(self.x,(800-self.h)/2)
        self:show()
    end
}

